package com.example.children.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.children.DTO.HealthCheckTeacherDTO;
import com.example.children.FileService.HealthCheckInterface;
import com.example.children.Mapper.HealthCheckMapper;
import com.example.children.Model.Behavior;
import com.example.children.Model.HealthCheck;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


    @Service  //体检
    public class HealthCheckService extends ServiceImpl<HealthCheckMapper, HealthCheck> implements HealthCheckInterface {

            @Autowired
            private HealthCheckMapper healthCheckMapper;

            public void addHealthCheck(HealthCheck healthCheck) {
                healthCheckMapper.insert(healthCheck);
            }

        //根据id查找
            public List<HealthCheck> getHealthChecksByStudent(String studentId) {
                return healthCheckMapper.selectByStudentId(studentId);
            }


        //根据日期查询日常
        public List<HealthCheck> selectByDateHealthCheck(HealthCheck healthChecks) {
            return healthCheckMapper.selectByDateSend(healthChecks);
        }


        //查询所有体检记录
        public Page<HealthCheckTeacherDTO> GetAllHealthCheck(int pageNo, int pageSize) {
            // 计算分页的偏移量
            int offset = (pageNo - 1) * pageSize;

            // 获取当前页的数据
            List<HealthCheckTeacherDTO> records = healthCheckMapper.GetAllHealthCheckTeacherDTO(offset, pageSize);
            // 获取总记录数
            int total = healthCheckMapper.countTotalRecords();
            // 构造并返回分页对象
            Page<HealthCheckTeacherDTO> page = new Page<>();
            page.setTotal(total);
            page.setSize(pageSize);
            page.setCurrent(pageNo);
            page.setRecords(records);

            return page;
        }

        //admin
        public List<HealthCheckTeacherDTO> AdminselectByDateSend(HealthCheckTeacherDTO healthCheckTeacherDTO) {
            return healthCheckMapper.AdminSelectByDateSend(healthCheckTeacherDTO);
        }


    }
